package com.heima.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ApArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * app端文章逻辑处理层
 *
 * @author 11494
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/3/3 20:39:33
 */
@Service
@Transactional
@Slf4j
public class ApArticleServiceImpl extends ServiceImpl<ApArticleMapper, ApArticle> implements ApArticleService {
    @Autowired
    private ApArticleMapper apArticleMapper;

    /**
     * 功能描述：加载文章列表
     *
     * @param apArticleDto
     * @param type
     * @return {@link ResponseResult }
     * @author sungang
     * @date 2024/03/03  20:50
     */
    @Override
    public ResponseResult load(ApArticleDto apArticleDto, int type) {
        //参数校验
        if (apArticleDto == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        //核心代码输出
        List<ApArticle> list = apArticleMapper.selectByCondition(apArticleDto, type);
        //结果封装返回
        return ResponseResult.okResult(list);
    }
}
